
module.exports = app => {
  const DataTypes = app.Sequelize;

  const Products = app.model.define(
    "products",
    {
      id: {
        type: DataTypes.INTEGER,
        allowNull: false,
        autoIncrement: true,
        primaryKey: true,
        comment: "商品表ID",
      },
      title: {
        type: DataTypes.STRING(255),
        allowNull: true,
        comment: "商品标题",
      },
      decs: {
        type: DataTypes.STRING(255),
        allowNull: true,
        comment: "商品描述",
      },
      price: {
        type: DataTypes.DECIMAL,
        allowNull: true,
        comment: "商品价格",
      },
      sort: {
        type: DataTypes.INTEGER,
        allowNull: true,
        defaultValue: 0,
        comment: "商品排序",
      },
      defaultImg: {
        type: DataTypes.STRING(255),
        allowNull: true,
        comment: "商品默认主图",
      },
      inventory: {
        type: DataTypes.INTEGER,
        defaultValue: 0,
        comment: "商品库存",
      },
      createdAt: {
        type: DataTypes.DATE,
        allowNull: true,
        comment: "创建时间",
      },
      updatedAt: {
        type: DataTypes.DATE,
        allowNull: true,
        comment: "更新时间",
      },
    },
    {
      tableName: "products",
    }
  );

  Products.associate = function () {
    // //一个商品属于一个购物车
    // app.model.Products.belongsTo(app.model.Shoppingcarts, {
    //   foreignKey: 'id',//定义联结关系中源模型的 key
    //   targetKey: 'pid'
    // });
    // app.model.Products.belongsToMany(app.model.Classes,
    //   {
    //     through: app.model.ProductsClasses,
    //     foreignKey: "pid",
    //     otherKey: "cid"
    //   })
  };

  return Products;
};
